package com.example.l2p_feedback;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class View03_CourseQuestion extends Activity {
	TextView tView, cView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view02_new_suggestion);

		Button button = (Button) findViewById(R.id.view0203_button_submit);
		button.setText("Submit question");

		button.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Context context = View03_CourseQuestion.this;
				SharedPreferences settings = PreferenceManager
						.getDefaultSharedPreferences(context);
				String token = settings.getString("token", "");
				tView = (TextView) findViewById(R.id.view0203_entry);
				cView = (TextView) findViewById(R.id.view0203_content);

				try {
					String msg;
					String url = "https://www.elearning.rwth-aachen.de/_vti_bin/l2pservices/api.svc/v1/addDiscussionThread?accessToken="
							+ token
							+ "&cid=14ss-38343&title="
							+ tView.getText().toString()
							+ "&contents="
							+ cView.getText().toString();
					new ApiCall(context).execute("GET", url).get();
					msg = "Question asked in Discussion Forum module\u2026";
					Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
				} catch (Exception e) {
					Log.e("L2P", e.getMessage());
				}
			}

		});

		this.setTitle("New Question");
	}
}
